define([
	'jquery',
	'underscore',
	'backbone',
	'moment',

	'baseView',
	'text!o2o/orgnization/tree.html',
	'js/myUtil.js'
], function($, _, Backbone, moment, BaseView, tpl, myUtil) {
	return BaseView.extend({
		render: function(cb) {
			var that = this;
			
			myUtil.getOrgnizationTree(function(err, res) {
				console.log('getOrgnizationTree res', res);
				if (that.showError(err, res)) return;
				var tmpl = _.template(tpl);
				var tmpl2 = tmpl({
					list: res.result
				})
				$(that.el).html(tmpl2);
				if (!$(this.el).is(":visible")) // if hide then show
					that.show();
				cb && cb();
			});
		},

		showError: function(err, res) {
			var nodeTip = $(this.el).find('.tip');
			if (err) return nodeTip.text(err).show();
			if (res.errCode !== 0) return nodeTip.text(res.errMsg).show();
			nodeTip.hide();
			return false; // no error
		}
	});
});